<template>
	<view class="componentsPart2">
		<view class="iconSetting">
			<buttonSpreadCompontVue :propsData="items" />
		</view>
		<view class="head">
			<view class="name">{{ items.name }}</view>
			<view class="serialNumber" v-if="isComponent">设备编号：{{ items.serialNumber }}</view>
			<view class="serialNumber" v-else>差旅编号：{{ items.serialNumber }}</view>
			<view class="number" v-if="isComponent">数量：{{ items.number }}</view>
			<view class="number" v-if="isComponent">单价：{{ items.unitPrice }}</view>
			<view class="costFront" v-if="isComponent">采购金额：{{ items.costFront }}</view>
			<view class="costFront" v-else>出差费用：{{ items.costFront }}</view>
			<view class="bill">发票：{{ bill }}</view>
			<view class="users" v-if="isComponent">购买人：{{ user.name }}</view>
			<view class="users" v-else>操作人：{{ user.name }}</view>
			<view class="paymentMethod">付款方式：{{ items.paymentMethod }}</view>
			<view class="createTime" v-if="isComponent">购买时间：{{ createDate }}</view>
			<view class="createTime" v-else>订单日期：{{ createDate }}</view>
			<view class="createTime" v-if="isComponent">最后操作时间：{{ updateDate }}</view>
			<view class="remark">备注：{{ items.remark }}</view>
		</view>
		<!-- 日志 -->
		<view class="body">
			<view class="contentLog">
				<view class="LogComponentVue" v-for="(item, index) in LogComponentVues">
					<logComponentVue :propsData="item" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { request } from '../../request';
import logComponentVue from '@/components/stockControl/logComponent.vue';
import buttonSpreadCompontVue from '../../components/buttonSpreadCompont/buttonSpreadCompont.vue';
export default {
	components: { logComponentVue, buttonSpreadCompontVue },
	computed: {
		createDate() {
			if (this.items.createTime != null) {
				return new Date(this.items.createTime).toISOString().split('T')[0];
			}
		},
		updateDate() {
			if (this.items.updateTime != null) {
				return new Date(this.items.updateTime).toISOString().split('T')[0];
			}
		},
		isComponent() {
			return this.items.type == 'component';
		}
	},
	data() {
		return {
			id: null,
			items: { name: null, serialNumber: null, number: null, costFront: null, paymentMethod: null, remark: null },
			bill: null,
			user: {
				name: null
			},
			LogComponentVues: [
				// {
				// 	users: '张三',
				// 	logText: '新增了元器件',
				// 	componentPart: 'PLC',
				// 	businessTrip: '外出',
				// 	project: '项目1',
				// 	createDate: '2025-03-23'
				// }
			]
		};
	},
	onLoad(item) {
		this.id = item.id;
		request('public/selectComponentById', { id: item.id }, 'GET').then((res) => {
			if (res.data.code != 200) {
				this.$message.error({
					message: '         ' + res.data.msg
				});
				return;
			}
			this.items = res.data.data;

			// 通过发票id获取发票
			request('public/selectBillById', { id: this.items.bill }, 'GET').then((res) => {
				this.bill = res.data.data.name + '  ==  ' + res.data.data.taxRate + '%';
			});

			// 通用户id获取用户
			request('public/selectUserById', { id: this.items.users }, 'GET').then((res) => {
				this.user = res.data.data;
			});
		});
	}
};
</script>

<style scoped>
/* 根容器样式 */
.componentsPart2 {
	width: 650rpx;
	max-width: 650rpx;
	margin: 20px auto;
	padding: 25px;
	background-color: white;
	border-radius: 16px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
	position: relative;
	overflow: hidden;
	font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
}
.iconSetting {
	position: absolute;
	margin: 10rpx 0 0 550rpx;
	z-index: 99;
}

/* 顶部装饰条 */
.componentsPart2::before {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 4px;
	background: linear-gradient(90deg, #409eff, #67c23a);
}

/* 标题区域 */
.head {
	padding-bottom: 20px;
	border-bottom: 1px solid #e6e6e6;
	margin-bottom: 20px;
}

.name {
	width: 550rpx;
	height: 80rpx;
	white-space: nowrap;
	overflow: scroll;
	font-size: 24px;
	font-weight: 600;
	color: #303133;
	margin-bottom: 15px;
	text-align: center;
	position: relative;
	padding-bottom: 10px;
}

/* 隐藏滚动条 */
::-webkit-scrollbar {
	display: none;
}

.name::after {
	content: '';
	position: absolute;
	bottom: 0;
	left: 60%;
	transform: translateX(-50%);
	width: 80px;
	height: 2px;
	background-color: #409eff;
	border-radius: 1px;
}

/* 数据分组布局 */
.data-group {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 15px;
	margin-top: 20px;
}

/* 数据项样式 */
.serialNumber,
.number,
.bill,
.costFront,
.users,
.paymentMethod,
.createTime,
.remark {
	font-size: 15px;
	color: #606266;
	margin-bottom: 0;
	display: flex;
	align-items: center;
	background-color: #fafafa;
	padding: 10px 15px;
	border-radius: 8px;
}

/* 数据项前缀标识 */
.serialNumber::before,
.number::before,
.bill::before,
.costFront::before,
.users::before,
.paymentMethod::before,
.createTime::before,
.remark::before {
	content: '';
	display: inline-block;
	width: 3px;
	height: 15px;
	background-color: #409eff;
	margin-right: 10px;
	border-radius: 1px;
}

/* 备注信息跨列显示 */
.remark {
	grid-column: 1 / -1;
	min-height: 60px;
	align-items: flex-start;
}

/* 信息内容强调 */
.serialNumber span,
.number span,
.bill span,
.costFront span,
.users span,
.paymentMethod span,
.createTime span,
.remark span {
	color: #303133;
	font-weight: 500;
	margin-left: 5px;
}

/* 底部区域 */
.footer {
	padding-top: 15px;
	border-top: 1px solid #e6e6e6;
	text-align: center;
	font-size: 13px;
	color: #909399;
	margin-top: 20px;
}

/* 响应式设计 */
@media (max-width: 640px) {
	.componentsPart2 {
		width: 90%;
		padding: 20px;
	}

	.data-group {
		grid-template-columns: 1fr;
	}
}

/* 动画效果 */
@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.componentsPart2 {
	animation: fadeIn 0.3s ease-out forwards;
}
</style>
